#define kMaxStringSize 1024
// CopyMyAudioDriverUID
// ÉhÉâÉCÉoÇà UID Çå©Ç¬ÇØÇƒÅA
// âï˙Ç∑Ç◊Ç´ CFString Ç…ï‘Ç∑
OSStatus CopyMyAudioDriverUID(CFStringRef *outUID)
{
UInt32 theSize;
char theString[kMaxStringSize];
UInt32 theNumberDevices;
AudioDeviceID *theDeviceList = NULL;
UInt32 theDeviceIndex;
CFStringRef theCFString = NULL;
OSStatus theStatus = noErr;
// DZÇÍÇ™ÉhÉâÉCÉo
const char *nameString = "BrownSound audio controller";
const char *manufacturerString = "Eddie";
*outUID = NULL;
// ÉfÉoÉCÉXÉäÉXÉgÇÃÉTÉCÉY
theSize = 0;
theStatus = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &theSize, NULL);
if (theStatus) goto done;
theNumberDevices = theSize / sizeof(AudioDeviceID);
// ÉfÉoÉCÉXÉäÉXÉgÇäÑÇËìñǃÇÈ
theDeviceList = (AudioDeviceID*)malloc(theNumberDevices * sizeof(AudioDeviceID));
// ÉfÉoÉCÉXÉäÉXÉgÇéÊìæÇ∑ÇÈ
theSize = theNumberDevices * sizeof(AudioDeviceID);
theStatus = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &theSize, theDeviceList);
// ÉfÉoÉCÉXÉäÉXÉgëSëÃÇ…ëŒÇµÇƒîΩïúèàóùÇçsÇ¢ÅA
// ÉfÉoÉCÉXÇå©Ç¬ÇØÇƒ UID Çï‘Ç∑
for(theDeviceIndex = 0; theDeviceIndex < theNumberDevices; ++theDeviceIndex)
{
// ñºëOÇéÊìæÇ∑ÇÈ
theSize = kMaxStringSize;
theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex],
0, 0, kAudioDevicePropertyDeviceName, &theSize, theString);
if (theStatus) goto done;
// àÍívǵǃǢÇÈÇ©ÅH
if (strncmp(theString, nameString, strlen(nameString)) == 0) {
// ÉÅÅ[ÉJÅ[èÓïÒÇéÊìæÇ∑ÇÈ
theSize = kMaxStringSize;
theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex], 0, 0,
kAudioDevicePropertyDeviceManufacturer, &theSize, theString);
if (theStatus) goto done;
// ñ{ìñÇ…àÍívǵǃǢÇÈÇ©ÅH
if (strncmp(theString, manufacturerString, strlen(manufacturerString)) == 0) {
// ÉfÉoÉCÉXÇà UID ÇéÊìæÇ∑ÇÈ
theSize = sizeof(CFStringRef);
theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex],
0, 0, kAudioDevicePropertyDeviceUID, &theSize, &theCFString);
if (theStatus) goto done;
*outUID = theCFString;
break;
}
}
}
// ÉfÉoÉCÉXÇÕå©Ç¬ÇÁǻǢ
if (NULL == *outUID) theStatus = badComponentType;
done:
// ÉfÉoÉCÉXÉäÉXÉgÇâï˙Ç∑ÇÈ
if (theDeviceList) free(theDeviceList);
return theStatus;
}
// QTVideoOutputGetIndSoundOutput
// ÉCÉìÉfÉbÉNÉXÉpÉâÉÅÉ^Ç≈éwíËÇ≥ÇÍÇΩÉrÉfÉIèoóÕÉRÉìÉ|Å[ÉlÉìÉgÇÃ
// ÉTÉEÉìÉhèoóÕÉRÉìÉ|Å[ÉlÉìÉgÇï‘Ç∑ÅBç≈èâÇÃÉRÉìÉ|Å[ÉlÉìÉgÇÃ
// ÉCÉìÉfÉbÉNÉXÇÕ 1
pascal ComponentResult MyVOut_GetIndSoundOutput(MyVOutGlobalsPtr storage,
long index, Component *outputComponent)
{
Component c = 0;
ComponentDescription cd = { kSoundOutputDeviceType, kHALCustomComponentSubType, 0, 0, 0 };
CFStringRef myUID = NULL;
CFStringRef halUID = NULL;
SMStatus ignore;
ComponentResult err;
*outputComponent = NULL;
// ÉTÉEÉìÉhèoóÕÉRÉìÉ|Å[ÉlÉìÉgÇÕ 1 ǬǵǩǻǢÇΩÇfl
// ÉCÉìÉfÉbÉNÉXÇ™ 1 à»äOÇÃèÍçáÇÕÉGÉâÅ[ÇΔÇ»ÇÈ
if (index != 1) return paramErr;
// Ç∑Ç≈DždžÇÈÇΩÇflÅAèIóπ
if (storage->soundOutput) {
*outputComponent = storage->soundOutput;
return noErr;
}
// core audio ÇégǡǃÅAÉIÅ[ÉfÉBÉIÉhÉâÉCÉo ID Çå©Ç¬ÇØÇÈ
err = CopyMyAudioDriverUID(&myUID);
if (err) goto bail;
// Sound Manager Çà¿âøÇ»ï˚ñ@Ç≈èâä˙âªÇ∑ÇÈÅBSound Manager ÇÕÉVÉXÉeÉÄè„ÇÃ
// Core Audio ÉhÉâÉCÉoÇ≤ÇΔÇ…ÉTÉEÉìÉhèoóÕÉRÉìÉ|Å[ÉlÉìÉgÇçáê¨Ç∑ÇÈÇΩÇflÅA
// DZÇÃèàóùÇ™ïKóv
SndManagerStatus(sizeof(SMStatus), &ignore);
// çáê¨Ç≥ÇÍÇΩÉTÉEÉìÉhèoóÕÉRÉìÉ|Å[ÉlÉìÉgÇå©Ç¬ÇØÇÈ
while (c = FindNextComponent(c, &cd)) {
// ï‘Ç≥ÇÍÇΩ CFString Çâï˙ǵǻǢ
err = SoundComponentGetInfo(c, 0, siHALAudioDeviceUniqueID, &halUID);
if (err) goto bail;
// àÍívÇ∑ÇÍÇŒê¨å˜
if (CFEqual(myUID, halUID)) {
*outputComponent = c;
storage->soundOutput = c;
break;
}
}
// ëŒâûÇ∑ÇÈ sDev Ç™å©Ç¬Ç©ÇÁǻǢ
if (NULL == *outputComponent) err = badComponentType;
bail:
if (myUID) CFRelease(myUID);
return err;
}
|